//
//  ClearViewController.m
//  miaopai
//
//  Created by Crow Zhang on 15/11/12.
//  Copyright © 2015年 Crow Zhang. All rights reserved.
//

#import "ClearViewController.h"
#import "JokeViewController.h"
#import "PicViewController.h"
#import "SameViewController.h"
#import "ILButton.h"

@interface ClearViewController ()

@property(nonatomic, retain)ILButton *videoButton;

@property(nonatomic, retain)ILButton *sameCityButton;

@property(nonatomic, retain)ILButton *jockeButton;

@property(nonatomic, retain)ILButton *picButton;

@property(nonatomic, retain)UIButton *closeButton;

@end

@implementation ClearViewController

- (void)dealloc
{
    [_videoButton release];
    [_sameCityButton release];
    [_jockeButton release];
    [_picButton release];
    [_closeButton release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor clearColor];
    
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    effectView.frame = self.view.frame;
    [self.view addSubview:effectView];
    [effectView release];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, kWidth, 30)];
    label.text = @"长按“＋”号可以直接录制视频哦";
    label.textColor = [UIColor grayColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    self.videoButton = [[ILButton alloc] initWithFrame:CGRectMake(0, 0, (kWidth - 90) / 2, (kWidth - 90) / 2)];
    self.videoButton.center = CGPointMake(self.videoButton.frame.size.width / 2 + 30, kHeight + self.videoButton.frame.size.width);
    self.videoButton.image.backgroundColor = [UIColor redColor];
    self.videoButton.image.image = [UIImage imageNamed:@"shiping"];
    self.videoButton.label.text = @"录制视频";
    [self.videoButton addMyTarget:self action:@selector(recodeVideo:)];
    [self.view addSubview:self.videoButton];
    [_videoButton release];
    
    self.sameCityButton = [[ILButton alloc] initWithFrame:CGRectMake(0, 0, (kWidth - 90) / 2, (kWidth - 90) / 2)];
    self.sameCityButton.center = CGPointMake(kWidth - (30 + self.sameCityButton.frame.size.width / 2), kHeight + self.sameCityButton.frame.size.width );
    self.sameCityButton.image.image = [UIImage imageNamed:@"yaoyiyao"];
    self.sameCityButton.image.backgroundColor = [UIColor yellowColor];
    self.sameCityButton.label.text = @"同城摇一摇";
    [self.sameCityButton addMyTarget:self action:@selector(toSameCity:)];
    [self.view addSubview:self.sameCityButton];
    [_sameCityButton release];
    
    self.jockeButton = [[ILButton alloc] initWithFrame:CGRectMake(0, 0, (kWidth - 90) / 2, (kWidth - 90) / 2)];
    self.jockeButton.center = CGPointMake(self.jockeButton.frame.size.width / 2 + 30, kHeight + self.jockeButton.frame.size.width);
    self.jockeButton.image.image = [UIImage imageNamed:@"joke"];
    self.jockeButton.image.backgroundColor = [UIColor cyanColor];
    self.jockeButton.label.text = @"段子";
    [self.jockeButton addMyTarget:self action:@selector(toJock:)];
    [self.view addSubview:self.jockeButton];
    [_jockeButton release];
    
    self.picButton = [[ILButton alloc] initWithFrame:CGRectMake(0, 0, (kWidth - 90) / 2, (kWidth - 90) / 2)];
    self.picButton.center = CGPointMake(kWidth - (30 + self.picButton.frame.size.width / 2), kHeight + self.picButton.frame.size.width);
    self.picButton.image.image = [UIImage imageNamed:@"tupian"];
    self.picButton.image.backgroundColor = [UIColor greenColor];
    self.picButton.label.text = @"图片";
    [self.picButton addMyTarget:self action:@selector(toPic:)];
    [self.view addSubview:self.picButton];
    [_picButton release];
    
    self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.closeButton.frame = CGRectMake((kWidth / 2 - 20), kHeight - 48, 40, 40);
    [self.closeButton setImage:[UIImage imageNamed:@"iconfont-plus-5"] forState:UIControlStateNormal];
    [self.closeButton setImage:[UIImage imageNamed:@"iconfont-plus-5"] forState:UIControlStateHighlighted];
    [self.closeButton addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.closeButton];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [UIView animateWithDuration:.2f animations:^{
        self.closeButton.transform = CGAffineTransformRotate(self.closeButton.transform, M_PI_4);
    }];
    [UIView animateWithDuration:0.5 delay:0.2 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.videoButton.center = CGPointMake(self.videoButton.frame.size.width / 2 + 30, kHeight - self.videoButton.frame.size.width * 1.5 - 48 - 20 - 30);
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0.3 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.sameCityButton.center = CGPointMake(kWidth - (30 + self.sameCityButton.frame.size.width / 2), kHeight - self.sameCityButton.frame.size.width * 1.5 - 48 - 20 - 30);
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0.3 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.jockeButton.center = CGPointMake(self.jockeButton.frame.size.width / 2 + 30, kHeight - self.jockeButton.frame.size.width * 0.5 - 48 - 10);
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0.4 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.picButton.center = CGPointMake(kWidth - (30 + self.picButton.frame.size.width / 2), kHeight - self.picButton.frame.size.width * 0.5 - 48 - 10);
    } completion:^(BOOL finished) {
        
    }];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [UIView animateWithDuration:.2f animations:^{
        self.closeButton.transform = CGAffineTransformRotate(self.closeButton.transform, -M_PI_4);
    }];
    [UIView animateWithDuration:0.5 delay:0.2 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.videoButton.center = CGPointMake(self.videoButton.frame.size.width / 2 + 30, kHeight + kHeight + self.videoButton.frame.size.width );
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0.1 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.sameCityButton.center = CGPointMake(kWidth - (30 + self.sameCityButton.frame.size.width / 2), kHeight + self.sameCityButton.frame.size.width );
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0.1 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.jockeButton.center = CGPointMake(self.jockeButton.frame.size.width / 2 + 30, kHeight - kHeight + self.jockeButton.frame.size.width);
    } completion:^(BOOL finished) {
        
    }];
    
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        self.picButton.center = CGPointMake(kWidth - (30 + self.picButton.frame.size.width / 2), kHeight + self.picButton.frame.size.width);
    } completion:^(BOOL finished) {
        
    }];
}

- (void)close:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)toSameCity:(UIButton *)sender
{
    SameViewController *sameCityView = [[SameViewController alloc] init];
    UINavigationController *sameCityNav = [[UINavigationController alloc] initWithRootViewController:sameCityView];
    [self dismissViewControllerAnimated:NO completion:nil];
    [self.delegate toView:sameCityNav];
    [sameCityView release];
    [sameCityNav release];
}

- (void)toJock:(UIButton *)sender
{
    JokeViewController *jockView = [[JokeViewController alloc] init];
    UINavigationController *jockNav = [[UINavigationController alloc] initWithRootViewController:jockView];
    [self dismissViewControllerAnimated:NO completion:nil];
    [self.delegate toView:jockNav];
    [jockNav release];
    [jockView release];
}

- (void)toPic:(UIButton *)sender
{
    PicViewController *picView = [[PicViewController alloc] init];
    UINavigationController *picNav = [[UINavigationController alloc] initWithRootViewController:picView];
    [self dismissViewControllerAnimated:NO completion:nil];
    [self.delegate toView:picNav];
    [picView release];
    [picNav release];
}

- (void)recodeVideo:(UIButton *)sender
{
    [self dismissViewControllerAnimated:NO completion:nil];
    [self.delegate recodeVideo];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
